#ifndef __MY_CONFIG__
#define __MY_CONFIG__
#include "util.hpp"

namespace  cloud{
#define CONFIG_FILE "cloud.conf"
    class Config{
        public:
            //获取单例对象
            static Config* GetInstance(){
                //c++11保证了静态变量创建时的线程安全
                static Config _eton;
                return &_eton;
            }
            //读取配置文件信息
            bool ReadConfigFile(){
                FileUtil fu(CONFIG_FILE);
                std::string body;
                if(fu.GetContent(&body) == false){
                    std::cout << "load config file error!\n";
                    return false;
                }
                //将序列化后的数据进行反序列化放入到json对象中
                Json::Value root;
                if(JsonUtil::UnSerialize(body, &root) == false){
                    std::cout << "parse config file error!\n";
                    return false;
                }
                _hot_time = root["hot_time"].asInt();
                _server_port = root["server_port"].asInt();
                _server_ip = root["server_ip"].asString();
                _download_prefix = root["download_prefix"].asString();
                _packfile_suffix = root["packfile_suffix"].asString();
                _pack_dir = root["pack_dir"].asString();
                _back_dir = root["back_dir"].asString();
                _backup_file = root["backup_file"].asString();
            }
            int GetHotTime(){
                return _hot_time;
            }
            int GetServerport(){
                return _server_port;
            }  
            std::string GetServerIp(){
                return _server_ip;
            }
            std::string GetDownLoadPrefix(){
                return _download_prefix;
            }
            std::string GetPackFileSuffix(){
                return _packfile_suffix;
            }
            std::string GetPackDir(){
                return _pack_dir;
            }
            std::string GetBackDir(){
                return _back_dir;
            }
            std::string GetBackupFile(){
                return _backup_file;
            }
        private:
            Config(){
                ReadConfigFile();
            }
            Config(const Config&) = delete;
            Config& operator=(const Config&) = delete;
        private:
            int _hot_time;
            int _server_port;
            std::string _server_ip;
            std::string _download_prefix;
            std::string _packfile_suffix;
            std::string _pack_dir;
            std::string _back_dir;
            std::string _backup_file;
    };
}


#endif